
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>StreamData · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="distillery.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">第一部分：基础</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../basics/basics.html">
            
                <a href="../basics/basics.html">
            
                    
                    基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../basics/collections.html">
            
                <a href="../basics/collections.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../basics/enum.html">
            
                <a href="../basics/enum.html">
            
                    
                    Enum 模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../basics/pattern-matching.html">
            
                <a href="../basics/pattern-matching.html">
            
                    
                    模式匹配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../basics/control-structures.html">
            
                <a href="../basics/control-structures.html">
            
                    
                    控制语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../basics/functions.html">
            
                <a href="../basics/functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../basics/pipe-operator.html">
            
                <a href="../basics/pipe-operator.html">
            
                    
                    管道操作符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../basics/modules.html">
            
                <a href="../basics/modules.html">
            
                    
                    模块(Module)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../basics/mix.html">
            
                <a href="../basics/mix.html">
            
                    
                    Mix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../basics/sigils.html">
            
                <a href="../basics/sigils.html">
            
                    
                    魔符(Sigil)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../basics/documentation.html">
            
                <a href="../basics/documentation.html">
            
                    
                    文档模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../basics/testing.html">
            
                <a href="../basics/testing.html">
            
                    
                    测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../basics/comprehensions.html">
            
                <a href="../basics/comprehensions.html">
            
                    
                    推导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../basics/strings.html">
            
                <a href="../basics/strings.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../basics/date-time.html">
            
                <a href="../basics/date-time.html">
            
                    
                    日期和时间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../basics/mix-tasks.html">
            
                <a href="../basics/mix-tasks.html">
            
                    
                    自定义Mix任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../basics/iex-helpers.html">
            
                <a href="../basics/iex-helpers.html">
            
                    
                    IEx辅助函数
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第二部分：高级</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../advanced/erlang.html">
            
                <a href="../advanced/erlang.html">
            
                    
                    和Erlang互操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../advanced/error-handling.html">
            
                <a href="../advanced/error-handling.html">
            
                    
                    错误处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../advanced/escripts.html">
            
                <a href="../advanced/escripts.html">
            
                    
                    可执行文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../advanced/concurrency.html">
            
                <a href="../advanced/concurrency.html">
            
                    
                    并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../advanced/otp-concurrency.html">
            
                <a href="../advanced/otp-concurrency.html">
            
                    
                    OTP并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../advanced/otp-supervisors.html">
            
                <a href="../advanced/otp-supervisors.html">
            
                    
                    OTP Supervisors
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../advanced/otp-distribution.html">
            
                <a href="../advanced/otp-distribution.html">
            
                    
                    OTP 分布式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="../advanced/metaprogramming.html">
            
                <a href="../advanced/metaprogramming.html">
            
                    
                    元编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="../advanced/umbrella-projects.html">
            
                <a href="../advanced/umbrella-projects.html">
            
                    
                    Umbrella Projects
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="../advanced/typespec.html">
            
                <a href="../advanced/typespec.html">
            
                    
                    Specifications and types
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="../advanced/behaviours.html">
            
                <a href="../advanced/behaviours.html">
            
                    
                    行为
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="../advanced/gen-stage.html">
            
                <a href="../advanced/gen-stage.html">
            
                    
                    GenStage
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="../advanced/protocols.html">
            
                <a href="../advanced/protocols.html">
            
                    
                    协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="../advanced/nerves.html">
            
                <a href="../advanced/nerves.html">
            
                    
                    Nerves
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第三部分：ECTO</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../ecto/basics.html">
            
                <a href="../ecto/basics.html">
            
                    
                    Basics
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../ecto/changesets.html">
            
                <a href="../ecto/changesets.html">
            
                    
                    Changesets
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../ecto/associations.html">
            
                <a href="../ecto/associations.html">
            
                    
                    关联关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../ecto/querying.html">
            
                <a href="../ecto/querying.html">
            
                    
                    查询
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第四部分：专题</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../specifics/plug.html">
            
                <a href="../specifics/plug.html">
            
                    
                    Plug
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../specifics/eex.html">
            
                <a href="../specifics/eex.html">
            
                    
                    嵌入的 Elixir(EEx)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../specifics/ets.html">
            
                <a href="../specifics/ets.html">
            
                    
                    Erlang 项式存储(ETS)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../specifics/mnesia.html">
            
                <a href="../specifics/mnesia.html">
            
                    
                    Mnesia 数据库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../specifics/debugging.html">
            
                <a href="../specifics/debugging.html">
            
                    
                    调试
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第五部分：程序库</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="guardian.html">
            
                <a href="guardian.html">
            
                    
                    Guardian(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="poolboy.html">
            
                <a href="poolboy.html">
            
                    
                    Poolboy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="benchee.html">
            
                <a href="benchee.html">
            
                    
                    Benchee
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="bypass.html">
            
                <a href="bypass.html">
            
                    
                    Bypass
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="distillery.html">
            
                <a href="distillery.html">
            
                    
                    Distillery(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="5.6" data-path="stream-data.html">
            
                <a href="stream-data.html">
            
                    
                    StreamData
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >StreamData</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x57FA;&#x4E8E;&#x7528;&#x4F8B;&#x7684;&#x5355;&#x5143;&#x6D4B;&#x8BD5;&#x5DE5;&#x5177;&#x5E93;&#xFF0C;&#x5982; <a href="https://hexdocs.pm/ex_unit/ExUnit.html" target="_blank">ExUnit</a> &#x662F;&#x5E2E;&#x52A9;&#x4F60;&#x9A8C;&#x8BC1;&#x4EE3;&#x7801;&#x662F;&#x5426;&#x4E0E;&#x9884;&#x671F;&#x8FD0;&#x884C;&#x903B;&#x8F91;&#x76F8;&#x7B26;&#x7684;&#x597D;&#x5DE5;&#x5177;&#x3002;&#x4F46;&#x662F;&#x57FA;&#x4E8E;&#x7528;&#x4F8B;&#x7684;&#x5355;&#x5143;&#x6D4B;&#x8BD5;&#x6709;&#x5B83;&#x7684;&#x7F3A;&#x70B9;&#xFF1A;</p>
<ul>
<li>&#x7531;&#x4E8E;&#x4F60;&#x53EA;&#x6D4B;&#x8BD5;&#x67D0;&#x4E00;&#x4E9B;&#x8F93;&#x5165;&#xFF0C;&#x4E00;&#x4E9B;&#x6781;&#x7AEF;&#x60C5;&#x51B5;&#x5F88;&#x5BB9;&#x6613;&#x88AB;&#x5FFD;&#x7565;&#x3002;</li>
<li>&#x4F60;&#x53EF;&#x80FD;&#x6CA1;&#x6709;&#x4ED4;&#x7EC6;&#x601D;&#x8003;&#x6E05;&#x695A;&#x9700;&#x6C42;&#x5C31;&#x80FD;&#x591F;&#x5199;&#x51FA;&#x8FD9;&#x4E9B;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#x3002;</li>
<li>&#x4EC5;&#x4E3A;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x7F16;&#x5199;&#x51E0;&#x4E2A;&#x6D4B;&#x8BD5;&#x6837;&#x4F8B;&#x4E5F;&#x53EF;&#x80FD;&#x4F1A;&#x975E;&#x5E38;&#x7E41;&#x7410;&#x3002;</li>
</ul>
<p>&#x672C;&#x6559;&#x7A0B;&#x5C06;&#x63A2;&#x7D22;&#x5982;&#x4F55;&#x4F7F;&#x7528; <a href="https://github.com/whatyouhide/stream_data" target="_blank">StreamData</a> &#x6765;&#x5E2E;&#x52A9;&#x6211;&#x4EEC;&#x514B;&#x670D;&#x4E0A;&#x8FF0;&#x7F3A;&#x70B9;&#x3002;</p>
<h2 id="&#x4EC0;&#x4E48;&#x662F;-streamdata">&#x4EC0;&#x4E48;&#x662F; StreamData?</h2>
<p><a href="https://github.com/whatyouhide/stream_data" target="_blank">StreamData</a> &#x662F;&#x8FDB;&#x884C;&#x57FA;&#x4E8E;&#x5C5E;&#x6027;&#x6765;&#x8FDB;&#x884C;&#x65E0;&#x72B6;&#x6001;&#x6D4B;&#x8BD5;&#x7684;&#x5DE5;&#x5177;&#x5E93;&#x3002;</p>
<p>&#x6BCF;&#x4E00;&#x4E2A;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#xFF0C;StreamData &#x90FD;&#x4F1A;&#x4F7F;&#x7528;&#x968F;&#x673A;&#x4EA7;&#x751F;&#x7684;&#x6570;&#x636E;<a href="https://hexdocs.pm/stream_data/ExUnitProperties.html#check/1-options" target="_blank">&#x9ED8;&#x8BA4;&#x8FD0;&#x884C; 100 &#x6B21;</a>&#x3002;&#x5F53;&#x4E00;&#x4E2A;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#x5931;&#x8D25;&#x540E;&#xFF0C;StreamData &#x4F1A;&#x5C1D;&#x8BD5;<a href="https://hexdocs.pm/stream_data/StreamData.html#module-shrinking" target="_blank">&#x7F29;&#x5C0F;</a>&#x5BFC;&#x81F4;&#x7528;&#x4F8B;&#x5931;&#x8D25;&#x7684;&#x8F93;&#x5165;&#x7684;&#x6700;&#x5C0F;&#x96C6;&#x3002;&#x8FD9;&#x5BF9;&#x4E8E;&#x4F60;&#x8C03;&#x8BD5;&#x4EE3;&#x7801;&#x6765;&#x8BF4;&#x662F;&#x975E;&#x5E38;&#x6709;&#x5E2E;&#x52A9;&#x7684;&#xFF01;&#x5982;&#x679C;&#x662F;&#x4E00;&#x4E2A;&#x62E5;&#x6709; 50 &#x4E2A;&#x5143;&#x7D20;&#x7684;&#x5217;&#x8868;&#x5BFC;&#x81F4;&#x4F60;&#x7684;&#x51FD;&#x6570;&#x8FD0;&#x884C;&#x51FA;&#x9519;&#xFF0C;&#x5E76;&#x53EA;&#x662F;&#x5176;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x662F;&#x6709;&#x95EE;&#x9898;&#x7684;&#xFF0C;StreamData &#x80FD;&#x5E2E;&#x4F60;&#x627E;&#x5230;&#x90A3;&#x4E2A;&#x5143;&#x7D20;&#x3002;</p>
<p>&#x8FD9;&#x4E2A;&#x6D4B;&#x8BD5;&#x5DE5;&#x5177;&#x5E93;&#x6709;&#x4E24;&#x4E2A;&#x4E3B;&#x8981;&#x7684;&#x6A21;&#x5757;&#x3002;<a href="https://hexdocs.pm/stream_data/StreamData.html" target="_blank"><code>StreamData</code></a> &#x8D1F;&#x8D23;&#x751F;&#x6210;&#x968F;&#x673A;&#x6570;&#x636E;&#x6D41;&#x3002;<a href="https://hexdocs.pm/stream_data/ExUnitProperties.htm" target="_blank"><code>ExUnitProperties</code></a> &#x8BA9;&#x4F60;&#x4F7F;&#x7528;&#x751F;&#x6210;&#x7684;&#x6570;&#x636E;&#x6765;&#x9488;&#x5BF9;&#x51FD;&#x6570;&#x7F16;&#x5199;&#x548C;&#x8FD0;&#x884C;&#x6D4B;&#x8BD5;&#x3002;</p>
<p>&#x4F60;&#x6216;&#x8BB8;&#x89C9;&#x5F97;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x90FD;&#x4E0D;&#x77E5;&#x9053;&#x51FD;&#x6570;&#x7684;&#x8F93;&#x5165;&#x662F;&#x4EC0;&#x4E48;&#xFF0C;&#x90A3;&#x600E;&#x4E48;&#x80FD;&#x5224;&#x65AD;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x662F;&#x5426;&#x80FD;&#x771F;&#x6B63;&#x8FDB;&#x884C;&#x6709;&#x6548;&#x6D4B;&#x8BD5;&#x5462;&#xFF1F;&#x522B;&#x7740;&#x6025;&#xFF0C;&#x63A5;&#x7740;&#x770B;&#x4F60;&#x5C31;&#x77E5;&#x9053;&#x4E86;&#xFF01;</p>
<h2 id="&#x5B89;&#x88C5;-streamdata">&#x5B89;&#x88C5; StreamData</h2>
<p>&#x9996;&#x5148;&#xFF0C;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; Mix &#x9879;&#x76EE;&#x3002;&#x5982;&#x679C;&#x9700;&#x8981;&#x5E2E;&#x52A9;&#x7684;&#x8BDD;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x53C2;&#x8003;<a href="https://elixirschool.com/en/lessons/basics/mix/#new-projects" target="_blank">&#x65B0;&#x5EFA;&#x9879;&#x76EE;</a> &#x8FD9;&#x4E2A;&#x7AE0;&#x8282;&#x3002;</p>
<p>&#x7136;&#x540E;&#xFF0C;&#x628A; StreamData &#x6DFB;&#x52A0;&#x5230; <code>mix.exs</code> &#x7684;&#x4F9D;&#x8D56;&#x4E2D;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-function"><span class="hljs-keyword">defp</span> <span class="hljs-title">deps</span></span> <span class="hljs-keyword">do</span>
  [{<span class="hljs-symbol">:stream_data</span>, <span class="hljs-string">&quot;~&gt; x.y&quot;</span>, <span class="hljs-symbol">only:</span> <span class="hljs-symbol">:test</span>}]
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x628A; <code>x</code> &#x548C; <code>y</code> &#x66FF;&#x6362;&#x4E3A; StreamData <a href="https://github.com/whatyouhide/stream_data#installation" target="_blank">&#x5B89;&#x88C5;&#x6307;&#x5F15;</a> &#x91CC;&#x7684;&#x7248;&#x672C;&#x53F7;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#x3002;</p>
<p>&#x6700;&#x540E;&#xFF0C;&#x5728;&#x547D;&#x4EE4;&#x884C;&#x8FD0;&#x884C;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#xFF1A;</p>
<pre><code>mix deps.get
</code></pre><h2 id="&#x4F7F;&#x7528;-streamdata">&#x4F7F;&#x7528; StreamData</h2>
<p>&#x4E3A;&#x4E86;&#x5C55;&#x793A; StreamData &#x7684;&#x7279;&#x6027;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x51C6;&#x5907;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x91CD;&#x590D;&#x8F93;&#x5165;&#x7684;&#x51FD;&#x6570;&#x3002;&#x5B83;&#x7684;&#x529F;&#x80FD;&#x5C31;&#x548C; <a href="https://hexdocs.pm/elixir/String.html#duplicate/2" target="_blank"><code>String.duplicate/2</code></a> &#x7C7B;&#x4F3C;&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x80FD;&#x590D;&#x5236;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5217;&#x8868;&#x6216;&#x5143;&#x7EC4;&#x3002;</p>
<h3 id="&#x5B57;&#x7B26;&#x4E32;">&#x5B57;&#x7B26;&#x4E32;</h3>
<p>&#x9996;&#x5148;&#xFF0C;&#x6211;&#x4EEC;&#x5199;&#x4E00;&#x4E2A;&#x80FD;&#x590D;&#x5236;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x51FD;&#x6570;&#x3002;&#x5B83;&#x7684;&#x9700;&#x6C42;&#x6709;&#x54EA;&#x4E9B;&#x5462;&#xFF1F;</p>
<ol>
<li>&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x5E94;&#x8BE5;&#x662F;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x3002;&#x8FD9;&#x662F;&#x9700;&#x8981;&#x590D;&#x5236;&#x7684;&#x6E90;&#x5B57;&#x7B26;&#x4E32;&#x3002;</li>
<li>&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x5E94;&#x8BE5;&#x662F;&#x4E00;&#x4E2A;&#x975E;&#x8D1F;&#x6570;&#x3002;&#x5B83;&#x6307;&#x5B9A;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x590D;&#x5236;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x53C2;&#x6570;&#x7684;&#x6B21;&#x6570;&#x3002;</li>
<li>&#x51FD;&#x6570;&#x9700;&#x8981;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x3002;&#x8FD4;&#x56DE;&#x7684;&#x65B0;&#x5B57;&#x7B26;&#x4E32;&#x5C31;&#x662F;&#x590D;&#x5236;&#x8FC7; 0 &#x6B21;&#x6216;&#x591A;&#x6B21;&#x6E90;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x7ED3;&#x679C;&#x3002;</li>
<li>&#x5982;&#x679C;&#x6E90;&#x5B57;&#x7B26;&#x4E32;&#x4E3A;&#x7A7A;&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x4E5F;&#x4E3A;&#x7A7A;&#x3002;</li>
<li>&#x5982;&#x679C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4E3A; 0&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x4E5F;&#x5E94;&#x8BE5;&#x4E3A;&#x7A7A;&#x3002;</li>
</ol>
<p>&#x5F53;&#x6211;&#x4EEC;&#x8FD0;&#x884C;&#x51FD;&#x6570;&#x65F6;&#xFF0C;&#x671F;&#x671B;&#x7684;&#x6548;&#x679C;&#x5E94;&#x8BE5;&#x662F;&#x8FD9;&#x6837;&#x7684;&#xFF1A;</p>
<pre><code class="lang-elixir">Repeater.duplicate(<span class="hljs-string">&quot;a&quot;</span>, <span class="hljs-number">4</span>)
<span class="hljs-comment"># &quot;aaaa&quot;</span>
</code></pre>
<p>Elixir &#x6709;&#x4E00;&#x4E2A; <code>String.duplicate/2</code> &#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x5E2E;&#x6211;&#x4EEC;&#x5904;&#x7406;&#x8FD9;&#x4E2A;&#x9700;&#x6C42;&#x3002;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x7684; <code>duplicate/2</code> &#x53EF;&#x4EE5;&#x59D4;&#x6258;&#x5B83;&#x53BB;&#x5904;&#x7406;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Repeater</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">duplicate</span></span>(string, times) <span class="hljs-keyword">when</span> is_binary(string) <span class="hljs-keyword">do</span>
    String.duplicate(string, times)
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x6B63;&#x5E38;&#x7684;&#x4F7F;&#x7528;&#x573A;&#x666F;&#x53EF;&#x4EE5;&#x5F88;&#x65B9;&#x4FBF;&#x7684;&#x4F7F;&#x7528; <a href="https://hexdocs.pm/ex_unit/ExUnit.html" target="_blank">ExUnit</a> &#x6765;&#x6D4B;&#x8BD5;&#x3002;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">RepeaterTest</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> ExUnit.Case

  describe <span class="hljs-string">&quot;duplicate/2&quot;</span> <span class="hljs-keyword">do</span>
    test <span class="hljs-string">&quot;creates a new string, with the first argument duplicated a specified number of times&quot;</span> <span class="hljs-keyword">do</span>
      assert <span class="hljs-string">&quot;aaaa&quot;</span> == Repeater.duplicate(<span class="hljs-string">&quot;a&quot;</span>, <span class="hljs-number">4</span>)
    <span class="hljs-keyword">end</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x4F46;&#xFF0C;&#x8FD9;&#x5E76;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x5168;&#x9762;&#x7684;&#x6D4B;&#x8BD5;&#x3002;&#x5982;&#x679C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4E3A; <code>0</code> &#x7684;&#x65F6;&#x5019;&#xFF0C;&#x7ED3;&#x679C;&#x5E94;&#x8BE5;&#x5982;&#x4F55;&#xFF1F;&#x5982;&#x679C;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4E3A;&#x7A7A;&#x5B57;&#x7B26;&#x4E32;&#x65F6;&#xFF0C;&#x7ED3;&#x679C;&#x53C8;&#x600E;&#x6837;&#xFF1F;&#x91CD;&#x590D;&#x4E00;&#x4E2A;&#x7A7A;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x610F;&#x4E49;&#x662F;&#x4EC0;&#x4E48;&#xFF1F;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x80FD;&#x5904;&#x7406; UTF-8 &#x7684;&#x5B57;&#x7B26;&#x5417;&#xFF1F;&#x51FD;&#x6570;&#x80FD;&#x5904;&#x7406;&#x5F88;&#x5927;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x5417;&#xFF1F;</p>
<p>&#x6211;&#x4EEC;&#x9700;&#x8981;&#x63D0;&#x4F9B;&#x66F4;&#x591A;&#x7684;&#x6837;&#x4F8B;&#x6765;&#x6D4B;&#x8BD5;&#x6781;&#x7AEF;&#x60C5;&#x51B5;&#x548C;&#x5927;&#x5B57;&#x7B26;&#x4E32;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x770B;&#x770B;&#x5982;&#x4F55;&#x4F7F;&#x7528; StreamData &#x6765;&#x66F4;&#x4E25;&#x683C;&#x5730;&#x6D4B;&#x8BD5;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x800C;&#x4E0D;&#x9700;&#x8981;&#x5199;&#x66F4;&#x591A;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">RepeaterTest</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> ExUnit.Case
  <span class="hljs-keyword">use</span> ExUnitProperties

  describe <span class="hljs-string">&quot;duplicate/2&quot;</span> <span class="hljs-keyword">do</span>
    property <span class="hljs-string">&quot;creates a new string, with the first argument duplicated a specified number of times&quot;</span> <span class="hljs-keyword">do</span>
      check all str &lt;- string(<span class="hljs-symbol">:printable</span>),
                times &lt;- integer(),
                times &gt;= <span class="hljs-number">0</span> <span class="hljs-keyword">do</span>

        assert ??? == Repeater.duplicate(str, times)
      <span class="hljs-keyword">end</span>
    <span class="hljs-keyword">end</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x7684;&#x4EE3;&#x7801;&#x662F;&#x4EC0;&#x4E48;&#x610F;&#x601D;&#x5462;&#xFF1F;</p>
<ul>
<li>&#x6211;&#x4EEC;&#x628A; <code>test</code> &#x66FF;&#x6362;&#x4E3A; <a href="https://github.com/whatyouhide/stream_data/blob/v0.4.2/lib/ex_unit_properties.ex#L109" target="_blank"><code>property</code></a>&#x3002;&#x8FD9;&#x662F;&#x63CF;&#x8FF0;&#x8981;&#x6D4B;&#x8BD5;&#x7684;&#x7279;&#x6027;&#x3002;</li>
<li><a href="https://hexdocs.pm/stream_data/ExUnitProperties.html#check/1" target="_blank"><code>check/1</code></a> &#x662F;&#x4E00;&#x4E2A;&#x5141;&#x8BB8;&#x6211;&#x4EEC;&#x8BBE;&#x7F6E;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x7684;&#x5B8F;&#x3002;</li>
<li><a href="https://hexdocs.pm/stream_data/StreamData.html#string/2" target="_blank"><code>StreamData.string/2</code></a> &#x8D1F;&#x8D23;&#x751F;&#x6210;&#x968F;&#x673A;&#x5B57;&#x7B26;&#x4E32;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x8C03;&#x7528; <code>string/2</code> &#x65F6;&#x4E0D;&#x4F20;&#x6A21;&#x5757;&#x540D;&#xFF0C;&#x56E0;&#x4E3A; <code>use ExUnitProperties</code> &#x8FD9;&#x4E2A;&#x5199;&#x6CD5; <a href="https://github.com/whatyouhide/stream_data/blob/v0.4.2/lib/ex_unit_properties.ex#L109" target="_blank">&#x5BFC;&#x5165; StreamData &#x51FD;&#x6570;</a>&#x3002;</li>
<li><code>StreamData.integer/0</code> &#x751F;&#x6210;&#x968F;&#x673A;&#x6574;&#x6570;&#x3002;</li>
<li><code>times &gt;= 0</code> &#x662F;&#x6761;&#x4EF6;&#x9632;&#x62A4;&#x8BED;&#x53E5;&#x3002;&#x5B83;&#x786E;&#x4FDD;&#x4EA7;&#x751F;&#x7684;&#x968F;&#x673A;&#x6574;&#x6570;&#x5FC5;&#x987B;&#x5927;&#x4E8E;&#x7B49;&#x4E8E;&#x96F6;&#x3002;&#x5176;&#x5B9E;&#x6709; <a href="https://hexdocs.pm/stream_data/StreamData.html#positive_integer/0" target="_blank"><code>SreamData.positive_integer/0</code></a> &#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x7B26;&#x5408;&#x6211;&#x4EEC;&#x7684;&#x9700;&#x6C42;&#xFF0C;&#x56E0;&#x4E3A; <code>0</code> &#x662F;&#x6211;&#x4EEC;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x7684;&#x6709;&#x6548;&#x53C2;&#x6570;&#x3002;</li>
</ul>
<p>&#x90A3;&#x4E2A; <code>???</code> &#x53EA;&#x662F;&#x6211;&#x6DFB;&#x52A0;&#x7684;&#x4F2A;&#x4EE3;&#x7801;&#x3002;&#x5177;&#x4F53;&#x6211;&#x4EEC;&#x8981;&#x600E;&#x4E48;&#x5199;&#x8FD9;&#x4E2A;&#x65AD;&#x8A00;&#x5462;&#xFF1F;&#x6211;&#x4EEC; <strong>&#x53EF;&#x4EE5;</strong> &#x8FD9;&#x4E48;&#x5199;&#xFF1A;</p>
<pre><code class="lang-elixir">assert String.duplicate(str, times) == Repeater.duplicate(str, times)
</code></pre>
<p>&#x4F46;&#x4F7F;&#x7528;&#x51FD;&#x6570;&#x7684;&#x5B9E;&#x9645;&#x5B9E;&#x73B0;&#x5E76;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x5E2E;&#x52A9;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5148;&#x628A;&#x6211;&#x4EEC;&#x7684;&#x65AD;&#x8A00;&#x6761;&#x4EF6;&#x653E;&#x677E;&#x4E00;&#x70B9;&#xFF0C;&#x6BD4;&#x5982;&#x6211;&#x4EEC;&#x5148;&#x53EA;&#x662F;&#x9A8C;&#x8BC1;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x957F;&#x5EA6;&#xFF1A;</p>
<pre><code class="lang-elixir">expected_length = String.length(str) * times
actual_length =
  str
  |&gt; Repeater.duplicate(times)
  |&gt; String.length()

assert actual_length == expected_length
</code></pre>
<p>&#x8FD9;&#x603B;&#x6BD4;&#x6CA1;&#x6709;&#x597D;&#xFF0C;&#x4F46;&#x8FD8;&#x4E0D;&#x5B8C;&#x7F8E;&#x3002;&#x8FD9;&#x4E2A;&#x6D4B;&#x8BD5;&#x8FD8;&#x662F;&#x80FD;&#x901A;&#x8FC7;&#x90A3;&#x4E9B;&#x4EA7;&#x751F;&#x6B63;&#x786E;&#x957F;&#x5EA6;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x51FD;&#x6570;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x771F;&#x6B63;&#x60F3;&#x9A8C;&#x8BC1;&#x7684;&#x4E24;&#x4E2A;&#x6761;&#x4EF6;&#x662F;&#xFF1A;</p>
<ol>
<li>&#x6211;&#x4EEC;&#x7684;&#x51FD;&#x6570;&#x751F;&#x6210;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x957F;&#x5EA6;&#x6B63;&#x786E;&#x3002;</li>
<li>&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x5185;&#x5BB9;&#x662F;&#x6E90;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x4E0D;&#x65AD;&#x91CD;&#x590D;&#x3002;</li>
</ol>
<p>&#x8FD9;&#x5176;&#x5B9E;&#x662F;<a href="https://www.propertesting.com/book_what_is_a_property.html#_alternate_wording_of_properties" target="_blank">&#x6539;&#x53D8;&#x63AA;&#x8F9E;&#x6765;&#x63CF;&#x8FF0;&#x7279;&#x6027;</a>&#x3002;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x6709;&#x9A8C;&#x8BC1;&#x7B2C;&#x4E00;&#x4E2A;&#x6761;&#x4EF6;&#x7684;&#x4EE3;&#x7801;&#x4E86;&#x3002;&#x4E3A;&#x4E86;&#x9A8C;&#x8BC1;&#x7B2C;&#x4E8C;&#x4E2A;&#x6761;&#x4EF6;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x628A;&#x7ED3;&#x679C;&#x5B57;&#x7B26;&#x4E32;&#x6309;&#x6E90;&#x5B57;&#x7B26;&#x4E32;&#x5206;&#x5272;&#xFF0C;&#x7136;&#x540E;&#x5F97;&#x5230;&#x7684;&#x662F;&#x4E00;&#x4E2A;&#x62E5;&#x6709;&#x96F6;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x7A7A;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x5217;&#x8868;&#x3002;</p>
<pre><code class="lang-elixir">list =
  str
  |&gt; Repeater.duplicate(times)
  |&gt; String.split(str)

assert Enum.all?(list, &amp;(&amp;<span class="hljs-number">1</span> == <span class="hljs-string">&quot;&quot;</span>))
</code></pre>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x628A;&#x8FD9;&#x4E24;&#x4E2A;&#x65AD;&#x8A00;&#x7ED3;&#x5408;&#x8D77;&#x6765;&#x770B;&#x770B;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">RepeaterTest</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> ExUnit.Case
  <span class="hljs-keyword">use</span> ExUnitProperties

  describe <span class="hljs-string">&quot;duplicate/2&quot;</span> <span class="hljs-keyword">do</span>
    property <span class="hljs-string">&quot;creates a new string, with the first argument duplicated a specified number of times&quot;</span> <span class="hljs-keyword">do</span>
      check all str &lt;- string(<span class="hljs-symbol">:printable</span>),
                times &lt;- integer(),
                times &gt;= <span class="hljs-number">0</span> <span class="hljs-keyword">do</span>
        new_string = Repeater.duplicate(str, times)

        assert String.length(new_string) == String.length(str) * times
        assert Enum.all?(String.split(new_string, str), &amp;(&amp;<span class="hljs-number">1</span> == <span class="hljs-string">&quot;&quot;</span>))
      <span class="hljs-keyword">end</span>
    <span class="hljs-keyword">end</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x548C;&#x539F;&#x6765;&#x7684;&#x6D4B;&#x8BD5;&#x4EE3;&#x7801;&#x76F8;&#x6BD4;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230; StreamData &#x8FD9;&#x4E2A;&#x7248;&#x672C;&#x662F;&#x539F;&#x6765;&#x7684;&#x4E24;&#x500D;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x5728;&#x539F;&#x6765;&#x7684;&#x6D4B;&#x8BD5;&#x4E0A;&#x6DFB;&#x52A0;&#x66F4;&#x591A;&#x7684;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#x7684;&#x8BDD;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">RepeaterTest</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> ExUnit.Case

  describe <span class="hljs-string">&quot;duplicating a string&quot;</span> <span class="hljs-keyword">do</span>
    test <span class="hljs-string">&quot;duplicates the first argument a number of times equal to the second argument&quot;</span> <span class="hljs-keyword">do</span>
      assert <span class="hljs-string">&quot;aaaa&quot;</span> == Repeater.duplicate(<span class="hljs-string">&quot;a&quot;</span>, <span class="hljs-number">4</span>)
    <span class="hljs-keyword">end</span>

    test <span class="hljs-string">&quot;returns an empty string if the first argument is an empty string&quot;</span> <span class="hljs-keyword">do</span>
      assert <span class="hljs-string">&quot;&quot;</span> == Repeater.duplicate(<span class="hljs-string">&quot;&quot;</span>, <span class="hljs-number">4</span>)
    <span class="hljs-keyword">end</span>

    test <span class="hljs-string">&quot;returns an empty string if the second argument is zero&quot;</span> <span class="hljs-keyword">do</span>
      assert <span class="hljs-string">&quot;&quot;</span> == Repeater.duplicate(<span class="hljs-string">&quot;a&quot;</span>, <span class="hljs-number">0</span>)
    <span class="hljs-keyword">end</span>

    test <span class="hljs-string">&quot;works with longer strings&quot;</span> <span class="hljs-keyword">do</span>
      alphabet = <span class="hljs-string">&quot;abcdefghijklmnopqrstuvwxyz&quot;</span>

      assert <span class="hljs-string">&quot;<span class="hljs-subst">#{alphabet}</span><span class="hljs-subst">#{alphabet}</span>&quot;</span> == Repeater.duplicate(alphabet, <span class="hljs-number">2</span>)
    <span class="hljs-keyword">end</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>StreamData &#x8FD9;&#x4E2A;&#x7248;&#x672C;&#x5176;&#x5B9E;&#x66F4;&#x77ED;&#x3002;&#x800C;&#x4E14; StreamData &#x8FD8;&#x80FD;&#x9632;&#x6B62;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x9057;&#x5FD8;&#x4E00;&#x4E9B;&#x6781;&#x7AEF;&#x60C5;&#x51B5;&#x3002;</p>
<h3 id="&#x5217;&#x8868;">&#x5217;&#x8868;</h3>
<p>&#x597D;&#xFF0C;&#x73B0;&#x5728;&#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x5199;&#x4E00;&#x4E2A;&#x91CD;&#x590D;&#x5217;&#x8868;&#x7684;&#x51FD;&#x6570;&#x3002;&#x6211;&#x4EEC;&#x5E0C;&#x671B;&#x5B83;&#x7684;&#x8868;&#x73B0;&#x884C;&#x4E3A;&#x662F;&#x8FD9;&#x6837;&#x7684;&#xFF1A;</p>
<pre><code class="lang-elixir">Repeater.duplicate([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], <span class="hljs-number">3</span>)
<span class="hljs-comment"># [1, 2, 3, 1, 2, 3, 1, 2, 3]</span>
</code></pre>
<p>&#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E2A;&#x6B63;&#x786E;&#xFF0C;&#x4F46;&#x662F;&#x4F4E;&#x6548;&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Repeater</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">duplicate</span></span>(list, <span class="hljs-number">0</span>) <span class="hljs-keyword">when</span> is_list(list) <span class="hljs-keyword">do</span>
    []
  <span class="hljs-keyword">end</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">duplicate</span></span>(list, times) <span class="hljs-keyword">when</span> is_list(list) <span class="hljs-keyword">do</span>
    list ++ duplicate(list, times - <span class="hljs-number">1</span>)
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>StreamData &#x7684;&#x6D4B;&#x8BD5;&#x770B;&#x8D77;&#x6765;&#x53EF;&#x80FD;&#x662F;&#x8FD9;&#x6837;&#x7684;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">RepeaterTest</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> ExUnit.Case
  <span class="hljs-keyword">use</span> ExUnitProperties

  describe <span class="hljs-string">&quot;duplicate/2&quot;</span> <span class="hljs-keyword">do</span>
    property <span class="hljs-string">&quot;creates a new list, with the elements of the original list repeated a specified number or times&quot;</span> <span class="hljs-keyword">do</span>
      check all list &lt;- list_of(term()),
                times &lt;- integer(),
                times &gt;= <span class="hljs-number">0</span> <span class="hljs-keyword">do</span>
        new_list = Repeater.duplicate(list, times)

        assert length(new_list) == length(list) * times

        if length(list) &gt; <span class="hljs-number">0</span> <span class="hljs-keyword">do</span>
          assert Enum.all?(Enum.chunk_every(new_list, length(list)), &amp;(&amp;<span class="hljs-number">1</span> == list))
        <span class="hljs-keyword">end</span>
      <span class="hljs-keyword">end</span>
    <span class="hljs-keyword">end</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4F7F;&#x7528;&#x4E86; <code>StreamData.list_of/1</code> &#x548C; <code>StreamData.term/0</code> &#x6765;&#x521B;&#x5EFA;&#x5305;&#x542B;&#x4E86;&#x4EFB;&#x610F;&#x7C7B;&#x578B;&#xFF0C;&#x4EFB;&#x610F;&#x957F;&#x5EA6;&#x7684;&#x5217;&#x8868;&#x3002;</p>
<p>&#x548C;&#x91CD;&#x590D;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x57FA;&#x4E8E;&#x5C5E;&#x6027;&#x7684;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#x7C7B;&#x4F3C;&#xFF0C;&#x6211;&#x4EEC;&#x628A;&#x6E90;&#x5217;&#x8868;&#x957F;&#x5EA6;&#x4E0E; <code>times</code> &#x7684;&#x4E58;&#x79EF;&#xFF0C;&#x548C;&#x7ED3;&#x679C;&#x5217;&#x8868;&#x7684;&#x957F;&#x5EA6;&#x8FDB;&#x884C;&#x5BF9;&#x6BD4;&#x3002;&#x7B2C;&#x4E8C;&#x4E2A;&#x65AD;&#x8A00;&#x9700;&#x8981;&#x7A0D;&#x5FAE;&#x89E3;&#x91CA;&#x4E00;&#x4E0B;&#xFF1A;</p>
<ol>
<li>&#x6211;&#x4EEC;&#x628A;&#x7ED3;&#x679C;&#x5217;&#x8868;&#x6309;&#x6E90;&#x5217;&#x8868; <code>list</code> &#x7684;&#x957F;&#x5EA6;&#x5207;&#x5206;&#x6210;&#x597D;&#x51E0;&#x6BB5;&#x3002;</li>
<li>&#x7136;&#x540E;&#x9A8C;&#x8BC1;&#x6BCF;&#x6BB5;&#x662F;&#x5426;&#x548C; <code>list</code> &#x76F8;&#x7B49;&#x3002;</li>
</ol>
<p>&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x786E;&#x4FDD;&#x7684;&#x662F;&#x6E90;&#x5217;&#x8868;&#x5728;&#x6700;&#x7EC8;&#x5217;&#x8868;&#x4E2D;&#x91CD;&#x590D;&#x4E86;&#x6B63;&#x786E;&#x7684;&#x6B21;&#x6570;&#xFF0C;&#x5E76;&#x4E14;&#x6CA1;&#x6709; <strong>&#x5176;&#x5B83;&#x4EFB;&#x4F55;</strong> &#x5143;&#x7D20;&#x5305;&#x542B;&#x5728;&#x6211;&#x4EEC;&#x7684;&#x7ED3;&#x679C;&#x5217;&#x8868;&#x4E2D;&#x3002;</p>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x4F7F;&#x7528;&#x6761;&#x4EF6;&#x5224;&#x65AD;&#x5462;&#xFF1F;&#x56E0;&#x4E3A;&#x7B2C;&#x4E00;&#x4E2A;&#x65AD;&#x8A00;&#x5DF2;&#x7ECF;&#x8BC1;&#x660E;&#x5728;&#x6E90;&#x5217;&#x8868;&#x548C;&#x7ED3;&#x679C;&#x5217;&#x8868;&#x957F;&#x5EA6;&#x4E3A; 0 &#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x5C31;&#x6CA1;&#x6709;&#x5FC5;&#x8981;&#x8FDB;&#x884C;&#x66F4;&#x591A;&#x7684;&#x5217;&#x8868;&#x6BD4;&#x8F83;&#x4E86;&#x3002;&#x800C;&#x4E14;&#xFF0C;<code>Enum.chunk_every/2</code> &#x7684;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x5FC5;&#x987B;&#x4E3A;&#x6B63;&#x6570;&#x3002;</p>
<h3 id="&#x5143;&#x7EC4;">&#x5143;&#x7EC4;</h3>
<p>&#x6700;&#x540E;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x5B9E;&#x73B0;&#x91CD;&#x590D;&#x5143;&#x7EC4;&#x7684;&#x51FD;&#x6570;&#x3002;&#x5B83;&#x7684;&#x8868;&#x73B0;&#x884C;&#x4E3A;&#x5E94;&#x8BE5;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-elixir">Repeater.duplicate({<span class="hljs-symbol">:a</span>, <span class="hljs-symbol">:b</span>, <span class="hljs-symbol">:c</span>}, <span class="hljs-number">3</span>)
<span class="hljs-comment"># {:a, :b, :c, :a, :b, :c, :a, :b, :c}</span>
</code></pre>
<p>&#x5176;&#x4E2D;&#x4E00;&#x79CD;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#x662F;&#x628A;&#x5143;&#x7EC4;&#x8F6C;&#x4E3A;&#x5217;&#x8868;&#xFF0C;&#x590D;&#x5236;&#x5217;&#x8868;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x8F6C;&#x4E3A;&#x5143;&#x7EC4;&#x3002;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Repeater</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">duplicate</span></span>(tuple, times) <span class="hljs-keyword">when</span> is_tuple(tuple) <span class="hljs-keyword">do</span>
    tuple
    |&gt; Tuple.to_list()
    |&gt; Repeater.duplicate(times)
    |&gt; List.to_tuple()
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x8FD9;&#x8981;&#x600E;&#x4E48;&#x6D4B;&#x8BD5;&#x5462;&#xFF1F;&#x8BA9;&#x6211;&#x4EEC;&#x5C1D;&#x8BD5;&#x4E00;&#x79CD;&#x548C;&#x4E4B;&#x524D;&#x4E0D;&#x540C;&#x7684;&#x65B9;&#x5F0F;&#x3002;&#x5BF9;&#x4E8E;&#x5B57;&#x7B26;&#x4E32;&#x548C;&#x5217;&#x8868;&#x6765;&#x8BF4;&#xFF0C;&#x6211;&#x4EEC;&#x6839;&#x636E;&#x6700;&#x540E;&#x7ED3;&#x679C;&#x7684;&#x957F;&#x5EA6;&#xFF0C;&#x548C;&#x5185;&#x5BB9;&#x6765;&#x65AD;&#x8A00;&#x3002;&#x7528;&#x540C;&#x6837;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x5904;&#x7406;&#x5143;&#x7EC4;&#x4E5F;&#x662F;&#x53EF;&#x4EE5;&#x7684;&#xFF0C;&#x53EA;&#x662F;&#x6D4B;&#x8BD5;&#x4EE3;&#x7801;&#x770B;&#x8D77;&#x6765;&#x5C31;&#x53EF;&#x80FD;&#x4E0D;&#x662F;&#x90A3;&#x4E48;&#x7B80;&#x5355;&#x6613;&#x61C2;&#x4E86;&#x3002;</p>
<p>&#x60F3;&#x60F3;&#x4E0B;&#x9762;&#x4E24;&#x4E2A;&#x4F60;&#x5904;&#x7406;&#x5143;&#x7EC4;&#x7684;&#x4E0D;&#x540C;&#x64CD;&#x4F5C;&#xFF1A;</p>
<ol>
<li>&#x8C03;&#x7528; <code>Repeater.duplicate/2</code> &#x6765;&#x5904;&#x7406;&#x5143;&#x7EC4;&#xFF0C;&#x628A;&#x7ED3;&#x679C;&#x8F6C;&#x6210;&#x5217;&#x8868;</li>
<li>&#x628A;&#x5143;&#x7EC4;&#x8F6C;&#x6210;&#x5217;&#x8868;&#xFF0C;&#x518D;&#x4F20;&#x5165; <code>Repeater.duplicate/2</code></li>
</ol>
<p>&#x8FD9;&#x5C31;&#x662F; Scott Wlaschin &#x63D0;&#x5230;&#x7684;&#x4E00;&#x79CD;&#x5E94;&#x7528;&#x6A21;&#x5F0F; <a href="https://fsharpforfunandprofit.com/posts/property-based-testing-2/#different-paths-same-destination" target="_blank">&quot;&#x4E0D;&#x540C;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x76F8;&#x540C;&#x7684;&#x7EC8;&#x70B9;&quot;</a>&#x3002;&#x8FD9;&#x4E24;&#x79CD;&#x4E0D;&#x540C;&#x7684;&#x5904;&#x7406;&#x987A;&#x5E8F;&#xFF0C;&#x6700;&#x540E;&#x751F;&#x6210;&#x7684;&#x7ED3;&#x679C;&#x5E94;&#x8BE5;&#x662F;&#x4E00;&#x6837;&#x7684;&#x3002;&#x8BA9;&#x6211;&#x4EEC;&#x7528;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x6765;&#x6D4B;&#x8BD5;&#x3002;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">RepeaterTest</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> ExUnit.Case
  <span class="hljs-keyword">use</span> ExUnitProperties

  describe <span class="hljs-string">&quot;duplicate/2&quot;</span> <span class="hljs-keyword">do</span>
    property <span class="hljs-string">&quot;creates a new tuple, with the elements of the original tuple repeated a specified number of times&quot;</span> <span class="hljs-keyword">do</span>
      check all t &lt;- tuple({term()}),
                times &lt;- integer(),
                times &gt;= <span class="hljs-number">0</span> <span class="hljs-keyword">do</span>
        result_1 =
          t
          |&gt; Repeater.duplicate(times)
          |&gt; Tuple.to_list()

        result_2 =
          t
          |&gt; Tuple.to_list()
          |&gt; Repeater.duplicate(times)

        assert result_1 == result_2
      <span class="hljs-keyword">end</span>
    <span class="hljs-keyword">end</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<h2 id="&#x603B;&#x7ED3;">&#x603B;&#x7ED3;</h2>
<p>&#x73B0;&#x5728;&#xFF0C;&#x6211;&#x4EEC;&#x6709;&#x4E86;&#x4E09;&#x4E2A;&#x5206;&#x522B;&#x590D;&#x5236;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5217;&#x8868;&#x548C;&#x5143;&#x7EC4;&#x7684;&#x51FD;&#x6570;&#x3002;&#x540C;&#x65F6;&#x4E5F;&#x62E5;&#x6709;&#x4E00;&#x4E9B;&#x57FA;&#x4E8E;&#x7279;&#x6027;&#x7684;&#x6D4B;&#x8BD5;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x6709;&#x5F88;&#x5927;&#x7684;&#x4FE1;&#x5FC3;&#x53EF;&#x4EE5;&#x8BA4;&#x5B9A;&#x51FD;&#x6570;&#x7684;&#x5B9E;&#x73B0;&#x662F;&#x6B63;&#x786E;&#x7684;&#x3002;</p>
<p>&#x6700;&#x540E;&#x7684;&#x5E94;&#x7528;&#x4EE3;&#x7801;&#x5E94;&#x8BE5;&#x662F;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Repeater</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">duplicate</span></span>(string, times) <span class="hljs-keyword">when</span> is_binary(string) <span class="hljs-keyword">do</span>
    String.duplicate(string, times)
  <span class="hljs-keyword">end</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">duplicate</span></span>(list, <span class="hljs-number">0</span>) <span class="hljs-keyword">when</span> is_list(list) <span class="hljs-keyword">do</span>
    []
  <span class="hljs-keyword">end</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">duplicate</span></span>(list, times) <span class="hljs-keyword">when</span> is_list(list) <span class="hljs-keyword">do</span>
    list ++ duplicate(list, times - <span class="hljs-number">1</span>)
  <span class="hljs-keyword">end</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">duplicate</span></span>(tuple, times) <span class="hljs-keyword">when</span> is_tuple(tuple) <span class="hljs-keyword">do</span>
    tuple
    |&gt; Tuple.to_list()
    |&gt; Repeater.duplicate(times)
    |&gt; List.to_tuple()
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x4E0B;&#x9762;&#x662F;&#x57FA;&#x4E8E;&#x7279;&#x6027;&#x7684;&#x6D4B;&#x8BD5;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">RepeaterTest</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> ExUnit.Case
  <span class="hljs-keyword">use</span> ExUnitProperties

  describe <span class="hljs-string">&quot;duplicate/2&quot;</span> <span class="hljs-keyword">do</span>
    property <span class="hljs-string">&quot;creates a new string, with the first argument duplicated a specified number of times&quot;</span> <span class="hljs-keyword">do</span>
      check all str &lt;- string(<span class="hljs-symbol">:printable</span>),
                times &lt;- integer(),
                times &gt;= <span class="hljs-number">0</span> <span class="hljs-keyword">do</span>
        new_string = Repeater.duplicate(str, times)

        assert String.length(new_string) == String.length(str) * times
        assert Enum.all?(String.split(new_string, str), &amp;(&amp;<span class="hljs-number">1</span> == <span class="hljs-string">&quot;&quot;</span>))
      <span class="hljs-keyword">end</span>
    <span class="hljs-keyword">end</span>

    property <span class="hljs-string">&quot;creates a new list, with the elements of the original list repeated a specified number or times&quot;</span> <span class="hljs-keyword">do</span>
      check all list &lt;- list_of(term()),
                times &lt;- integer(),
                times &gt;= <span class="hljs-number">0</span> <span class="hljs-keyword">do</span>
        new_list = Repeater.duplicate(list, times)

        assert length(new_list) == length(list) * times

        if length(list) &gt; <span class="hljs-number">0</span> <span class="hljs-keyword">do</span>
          assert Enum.all?(Enum.chunk_every(new_list, length(list)), &amp;(&amp;<span class="hljs-number">1</span> == list))
        <span class="hljs-keyword">end</span>
      <span class="hljs-keyword">end</span>
    <span class="hljs-keyword">end</span>

    property <span class="hljs-string">&quot;creates a new tuple, with the elements of the original tuple repeated a specified number of times&quot;</span> <span class="hljs-keyword">do</span>
      check all t &lt;- tuple({term()}),
                times &lt;- integer(),
                times &gt;= <span class="hljs-number">0</span> <span class="hljs-keyword">do</span>
        result_1 =
          t
          |&gt; Repeater.duplicate(times)
          |&gt; Tuple.to_list()

        result_2 =
          t
          |&gt; Tuple.to_list()
          |&gt; Repeater.duplicate(times)

        assert result_1 == result_2
      <span class="hljs-keyword">end</span>
    <span class="hljs-keyword">end</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x6700;&#x540E;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x547D;&#x4EE4;&#x884C;&#x8F93;&#x5165;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x6765;&#x8FD0;&#x884C;&#x6D4B;&#x8BD5;&#xFF1A;</p>
<pre><code>mix test
</code></pre><p>&#x8BB0;&#x4F4F;&#xFF0C;&#x6BCF;&#x4E2A; StreamData &#x6D4B;&#x8BD5;&#x90FD;&#x4F1A;&#x9ED8;&#x8BA4;&#x8FD0;&#x884C; 100 &#x6B21;&#x3002;&#x800C;&#x4E14;&#xFF0C;&#x6709;&#x4E9B; StreamData &#x7684;&#x968F;&#x673A;&#x6570;&#x636E;&#x9700;&#x8981;&#x66F4;&#x591A;&#x65F6;&#x95F4;&#x6765;&#x751F;&#x6210;&#x3002;&#x6240;&#x4EE5;&#xFF0C;&#x7D2F;&#x79EF;&#x7684;&#x6548;&#x679C;&#x5C31;&#x662F;&#x8FD9;&#x4E9B;&#x6D4B;&#x8BD5;&#x4F1A;&#x6BD4;&#x57FA;&#x4E8E;&#x7528;&#x4F8B;&#x7684;&#x6D4B;&#x8BD5;&#x4F1A;&#x6162;&#x597D;&#x4E00;&#x4E9B;&#x3002;</p>
<p>&#x5373;&#x4FBF;&#x8FD9;&#x6837;&#xFF0C;&#x57FA;&#x4E8E;&#x7279;&#x6027;&#x7684;&#x6D4B;&#x8BD5;&#x662F;&#x57FA;&#x4E8E;&#x7528;&#x4F8B;&#x7684;&#x6D4B;&#x8BD5;&#x7684;&#x5F88;&#x597D;&#x7684;&#x8865;&#x5145;&#x3002;&#x5B83;&#x5141;&#x8BB8;&#x6211;&#x4EEC;&#x901A;&#x8FC7;&#x7B80;&#x660E;&#x7684;&#x6D4B;&#x8BD5;&#x6765;&#x8986;&#x76D6;&#x5927;&#x8303;&#x56F4;&#x7684;&#x8F93;&#x5165;&#x60C5;&#x51B5;&#x3002;&#x5982;&#x679C;&#x4F60;&#x4E0D;&#x9700;&#x8981;&#x5728;&#x6BCF;&#x4E2A;&#x6D4B;&#x8BD5;&#x4E4B;&#x95F4;&#x7EF4;&#x62A4;&#x72B6;&#x6001;&#xFF0C;StreamData &#x63D0;&#x4F9B;&#x5F88;&#x597D;&#x7684;&#x8BED;&#x6CD5;&#x6765;&#x7F16;&#x5199;&#x57FA;&#x4E8E;&#x7279;&#x6027;&#x7684;&#x6D4B;&#x8BD5;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="distillery.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: Distillery(基础)">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"version":"1.0.0","title":"StreamData","level":"5.6","depth":1,"previous":{"title":"Distillery(基础)","level":"5.5","depth":1,"path":"lessons/libraries/distillery.md","ref":"lessons/libraries/distillery.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"lessons/libraries/stream-data.md","mtime":"2019-11-05T02:25:51.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-11-05T03:01:22.004Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

